Skip to content

Fix using a non-tuple sequence for multidimensional indexing that wil…#8732

Open
aarpon wants to merge 2 commits intoProject-MONAI:devfrom
aitoo:fix/non_tuple_indexing
Open

Fix using a non-tuple sequence for multidimensional indexing that wil…#8732
aarpon wants to merge 2 commits intoProject-MONAI:devfrom
aitoo:fix/non_tuple_indexing

Conversation

@aarpon
Copy link

@aarpon aarpon commented Feb 5, 2026

Fix using a non-tuple sequence for multidimensional indexing that will result in error in pytorch 2.9.

Fixes # .

Description

The SlidingWindowInferer complains that from PyTorch 2.9, using non-tuple sequences to slice into Tensors will result in an error (or, worse, misbehave). This patch targets all places in monai/inferers/utils.py where indexing may happen with lists or other types of sequences.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

This PR updates monai/inferers/utils.py to normalize tensor indexing across sliding-window inference by converting list-based indices to tuples. Changes apply to batched and non-batched paths when gathering window data and conditions, updating the sliding-window device buffer and final outputs, and when accumulating patch contributions in _compute_coords. No public API signatures are changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly describes the main change: fixing non-tuple sequence indexing for PyTorch 2.9 compatibility in tensor operations.
Description check ✅ Passed Description covers the issue, solution, and includes required testing checkboxes. Key sections present: problem statement, description, and types of changes with test verification.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant